(function() {
	Path.on("/user/__basename__.html", function(_current_location) {
		var q = _current_location.query;
		var t = q.get("type");
		if (t == 2) {
			App.set('$Cache.user.collection.title', '商品收藏');
			App.set('$Cache.user.collection.infotype', 'focus');
			coAjax.get(appConfig.user.collect_detail, function(result) {
				App.set("$Cache.user.collection.collect_detail", result.result);
			}, function(c, x, m) {
				alert("error", m);
			});
		} else {
			App.set('$Cache.user.collection.title', '店铺收藏');
			App.set('$Cache.user.collection.infotype', '');
			coAjax.get(appConfig.user.collectBus_with_goods_info, function(o) {
				App.set("$Cache.user.collection.collectBus_with_goods_info", o.result)
			}, function(c, x, m) {
				alert("error", m);
			});
		};
	})
	App.set("$Event.user.collection.remove_goods_from_collect", function(e, vm) {
		coAjax["delete"](appConfig.user.collect_remove, {
			goods_id: vm.get("_id")
		}, function(result) {
			alert("成功把商品取消收藏");
			vm.removeFromArray();
		}, function(errorCode, xhr, errorMsg) {
			alert("error", errorMsg);
		});
	});

	App.set("$Event.user.collection.collect_goods_add_to_cart", function(e, vm) {
		var cart_item = {
			goods_id: vm.get("_id"),
			num: 1
		};
		coAjax.post(appConfig.user.cart, cart_item, function _get_cart_success(result) {
			alert("success", "添加成功")
		}, function(errorCode, xhr, errorMsg) {
			alert("error", errorMsg);
		});

	});

	App.set("$Event.user.collection.remove_collect_bus", function(e, vm) {
		coAjax["delete"](appConfig.user.collectBus_remove, {
			bus_id: vm.get("_id")
		}, function(result) {
			alert("success", "已经取消收藏");
			vm.removeFromArray();
			_load_collect_bus();
		}, function(errorCode, xhr, errorMsg) {
			alert("error", errorMsg)
		});
	});

	function _load_collect_bus() {
		coAjax.get(appConfig.user.collectBus_with_goods_info, function(result) {
			App.set("$Cache.user.collection.collectBus_with_goods_info", result.result);
		}, function(errorCode, xhr, errorMsg) {
			alert("error", errorMsg);
		});
	}
}());